package com.gzy.wbapplication.manager;

import android.content.Context;
import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.gzy.wbapplication.LoginActivity;
import com.gzy.wbapplication.StartActivity;
import com.gzy.wbapplication.model.User;
import com.gzy.wbapplication.utils.SPUtils;

public class AuthManager {
    public static boolean isLogin(Context startActivity){
        return !TextUtils.isEmpty(SPUtils.read(startActivity,"Token"));
    }

    public static void login(Context context, String token, User data) {
        SPUtils.save(context,"Token",token);
        SPUtils.save(context,"Userinfo", JSON.toJSONString(data));
    }

    public static String loadToken(Context context){
        String token = SPUtils.read(context, "Token");
        return token;
    }
    public static User loadUser(Context context){
        String userinfo = SPUtils.read(context, "Userinfo");
        return JSON.parseObject(userinfo,User.class);
    }

    public static void logout(Context context) {
        SPUtils.clear(context);

    }
}
